package com.tangqi.android;

import com.tangqi.android.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
//import android.widget.TextView;

public class AddActivity extends Activity {

    private TextView tvName = null;
    private TextView tvPhone = null;
    
	private Button saveBtn = null;
	private Button cancelBtn = null;
	
	PersonService personService = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		       
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add);	
		personService = new PersonService(this.getBaseContext());
	     
		 tvName = (TextView)findViewById(R.id.name);
	     tvPhone = (TextView)findViewById(R.id.phone);  
	        
	     saveBtn = (Button) findViewById(R.id.saveBtn);
	     saveBtn.setOnClickListener(listener);
	        
	     cancelBtn = (Button) findViewById(R.id.cancelBtn);
	     cancelBtn.setOnClickListener(listener);
	}
	
	private OnClickListener listener = new OnClickListener() {
		public void onClick(View v) {
			Button btn = (Button) v;
			Intent intent = new Intent();
			switch (btn.getId()) {
			case R.id.saveBtn:
				save();
				intent.setClass(AddActivity.this, SQLiteDemo.class);
				break;
			case R.id.cancelBtn:
				intent.setClass(AddActivity.this, SQLiteDemo.class);
				break;
			}
			startActivity(intent);
		}
	};
	
	public void save(){
		Person person = new Person();
		person.setName(tvName.getText().toString());
		person.setPhone(tvPhone.getText().toString());
		personService.save(person);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

}
